package com.ddzh.controller;

import com.ddzh.pojo.Order;
import com.ddzh.service.ConsumerService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.Set;

@RestController
@RequestMapping("consumer")
public class ConsumerController {

    @Autowired
    private ConsumerService consumerService;

    @GetMapping("{username}")
//    @HystrixCommand(fallbackMethod = "findUserById")
    public Map<String, List<Order>> findUserById(@PathVariable("username") String username) {
        //查询用户信息
        Map<String, List<Order>> resMap = consumerService.findUserById(username);
        Set<Map.Entry<String, List<Order>>> entries = resMap.entrySet();

        for (Map.Entry<String, List<Order>> entry : entries) {
            String key = entry.getKey();
            List<Order> value = entry.getValue();
            System.out.println( key +" = " + value);
        }
        return resMap;
    }


//    public Map<String, List<Order>> findUserById(String username) {
//        Map<String, List<Order>> resMap = consumerService.findUserById(username);
//        resMap.put("暂停服务",null);
//        return resMap;
//    }
}

